import React from 'react';
import { HashRouter, Route, Switch } from 'react-router-dom';

/*
 * @Description: 路由自动填充查找
 * @Date: 2020-10-22 09:10:19
 * @LastEditTime: 2020-10-22 11:18:30
 */
let routes = []
const files = require.context(
  "./routes",
  false,
  /^(?!\.\/index\b).*\.js$/
);

files.keys().forEach(key => {
  const file = files(key);
  routes = routes.concat(file.default);
});

const BasicRoute = () => (
  <HashRouter>
    <Switch>
      {
        routes.map((item, index) => (
          <Route
            key={index}
            exact
            path={item.path}
            component={item.component}
          />
        ))
      }
    </Switch>
  </HashRouter>
)

export default BasicRoute;